package com.example.springbootchapter09.config;

import com.example.springbootchapter09.quzrtz.QuartzJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail quartzJobDetail() {
        return JobBuilder.newJob(QuartzJob.class)
                .withIdentity("quartzJob")
                .storeDurably()
                .build();
    }
    @Bean
    public Trigger quartzJobTrigger() {
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0/5 * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(quartzJobDetail())
                .withIdentity("quartzJobTrigger")
                .withSchedule(cronScheduleBuilder)
                .build();
    }
}